﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TBR.Resources;
using TBR.Repositories;
using System.IO;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace TBR
{
    public partial class MainPage : PhoneApplicationPage
    {
        #region events
        private void accountRepository_GoHomePageCompleted(object sender, TBR.Repositories.AccountRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            webHtml.NavigateToString(args.HtmlCode);
        }

        private void accountRepository_AuthorizeCompleted(object sender, TBR.Repositories.AccountRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            webHtml.NavigateToString(args.HtmlCode);
        }
        private void friendsRepository_FriendsCompleted(object sender, TBR.Repositories.FriendsRepository.RequestEventArgs args)
        {
           

            //html.Text = args.HtmlCode;
            //webHtml.NavigateToString(args.HtmlCode);
        }
        private void invitesRepository_GetInvitesCompleted(object sender, TBR.Repositories.InvitesRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            //webHtml.NavigateToString(args.HtmlCode);
        }

        private void guestRepository_GetGuestsCompleted(object sender, TBR.Repositories.GuestRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            //webHtml.NavigateToString("Няма нiчога");
        }

        private void messageRepository_GetMessagesCompleted(object sender, TBR.Repositories.MessageRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            //webHtml.NavigateToString("Няма нiчога");
        }

        private void dialogRepository_GetDialogCompleted(object sender, TBR.Repositories.DialogRepository.RequestEventArgs args)
        {
            //html.Text = args.HtmlCode;
            //webHtml.NavigateToString("Няма нiчога");
        }
        #endregion

        #region properties
        private AccountRepository accountRepository { get; set; }
        private FriendsRepository friendsRepository { get; set; }
        private GuestRepository guestRepository { get; set; }
        private MessageRepository messageRepository { get; set; }
        private DialogRepository dialogRepository { get; set; }
        private InvitesRepository invitesRepository { get; set; }
        private ProfileRepository profileRepository { get; set; }
        #endregion

        #region constructor
        public MainPage()
        {
            InitializeComponent();
            accountRepository = new AccountRepository();
            friendsRepository = new FriendsRepository();
            guestRepository = new GuestRepository();
            messageRepository = new MessageRepository();
            dialogRepository = new DialogRepository();
            invitesRepository = new InvitesRepository();
            profileRepository = new ProfileRepository();
            accountRepository.GoHomePageCompleted += accountRepository_GoHomePageCompleted;
            accountRepository.AuthorizeCompleted += accountRepository_AuthorizeCompleted;
            friendsRepository.GetFriendsPageCompleted += friendsRepository_FriendsCompleted;
            guestRepository.GetGuestCompleted += guestRepository_GetGuestsCompleted;
            messageRepository.GetMessagesCompleted += messageRepository_GetMessagesCompleted;
            dialogRepository.GetDialogCompleted += dialogRepository_GetDialogCompleted;
            invitesRepository.GetInvitesPageCompleted += invitesRepository_GetInvitesCompleted;
            profileRepository.GetProfilePageCompleted += profileRepository_GetProfilePageCompleted;
            //invitesRepository.ApproveCompleted += invitesRepository_ApproveCompleted;
            //accountRepository.Authorize("romandrovich", "20081990");//your credentials
        }

        void profileRepository_GetProfilePageCompleted(object source, ProfileRepository.RequestEventArgs args)
        {
           
        }

        #endregion

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            accountRepository.Authorize("romandro", "20081990");//your credentials
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
          //  NavigationService.Navigate(new Uri("/NavigationPage.xaml", UriKind.Relative));
           // friendsRepository.GoFrieds();
            //invitesRepository.GoInvites();
           // invitesRepository.ApproveInvite(6362635);
            

        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            //guestRepository.GetGuest();
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            //messageRepository.GetMessages();
        }

        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            //dialogRepository.GetDialog(6955718);
        }
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            profileRepository.GetProfile();     
        }
        private void Button_Click_7(object sender, RoutedEventArgs e)
        {
            profileRepository.GetProfile("6787012");
        }
        private void Button_Click_8(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainProfilePage.xaml", UriKind.Relative));
        }
        private void Button_Click_9(object sender, RoutedEventArgs e)
        {
            profileRepository.SetState("Пришёл");  
        }
        private void Button_Click_10(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PeoplePage.xaml", UriKind.Relative));
        }
        private void Button_Click_11(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PanoramaMessages.xaml?page=Messages", UriKind.Relative));
        }
    }
}